package com.hxd.otc.module.home.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.common.enums.MessageTypeEnum;
import com.hxd.otc.module.my.bean.MessageBean;
import com.hxd.otc.utils.DateUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2019/1/17 0017.
 * description ${消息Adapter}
 */
public class MessageAdapter extends BaseAdapter<MessageAdapter.MessageHolder, MessageBean> {
    public MessageAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull MessageHolder holder, int position) {
        MessageBean item = getItem(position);
        MessageTypeEnum messageTypeEnum = MessageTypeEnum.getInstance(item.getType());
        holder.tvTitle.setText(messageTypeEnum.getDesc());
        holder.tvContent.setText(item.getTitle());
        holder.tvDate.setText(DateUtil.format(Long.parseLong(item.getCreateDate()), DateUtil.YY_MM_DD_HH_MM_SS));
    }

    @NonNull
    @Override
    public MessageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MessageHolder(mInflater.inflate(R.layout.item_message, parent, false));
    }

    static class MessageHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_red)
        ImageView ivRed;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_content)
        TextView tvContent;

        MessageHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
